public class demo2 {
    public static void main1(String[] args) throws InterruptedException {//创建线程20个
        Thread t0=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t1=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t2=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t3=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t4=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t5=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t6=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t7=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t8=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t9=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t10=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t11=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t12=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t13=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t14=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t15=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t16=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t17=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t18=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t19=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        Thread t20=new Thread(()-> {
            System.out.println(Thread.currentThread().getName());
        });
        t0.start();
        t0.join();
        t1.start();
        t1.join();
        t2.start();
        t2.join();
        t3.start();
        t3.join();
        t4.start();
        t4.join();
        t5.start();
        t5.join();
        t6.start();
        t6.join();
        t7.start();
        t7.join();
        t8.start();
        t8.join();
        t9.start();
        t9.join();
        t10.start();
        t10.join();
        t11.start();
        t11.join();
        t12.start();
        t12.join();
        t13.start();
        t13.join();
        t14.start();
        t14.join();
        t15.start();
        t15.join();
        t16.start();
        t16.join();
        t17.start();
        t17.join();
        t18.start();
        t18.join();
        t19.start();
        t19.join();
        t20.start();
        t20.join();
        System.out.println("ok");
    }
    public static void main2(String[] args) throws InterruptedException {//创建线程20个，写法更简洁
        Thread[] threads=new Thread[20];
        for(int i=0;i<threads.length;i++){
            threads[i]=new Thread(()-> {
                System.out.println(Thread.currentThread().getName());
            });
        }
        for (Thread thread : threads) {
            thread.start();
            thread.join();
        }
        System.out.println("ok");
    }
    public static void main(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("1");
            }
        });
        t.start();
        System.out.println("2");
    }
}
